package com.suneast.suneaststore.modules.personal.address.adapter;

import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.personal.address.AddressBean;

public class AddressListAdapter extends BaseQuickAdapter<AddressBean, BaseViewHolder> {

    public AddressListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, AddressBean item) {
        helper.setText(R.id.tv_name, item.getRealname())
                .setText(R.id.tv_phone_number, item.getMobile())
                .setText(R.id.tv_address, item.getProvince() + item.getCity() + item.getArea()
                        + item.getTown() + " " + item.getAddress())
                .addOnClickListener(R.id.tv_edit_address)
                .addOnClickListener(R.id.tv_delete_address)
                .addOnClickListener(R.id.tv_address);
        RadioButton rb = helper.getView(R.id.rb_set_default);
        rb.setChecked(item.getIsdefault() == 1);
        rb.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
            if (listener != null) {
                listener.onCheckChange(item.getId(), isChecked);
            }
        });
    }

    public interface CheckChangeListener {
        void onCheckChange(int id, boolean isChecked);
    }

    private CheckChangeListener listener;

    public void setCheckChangeListener(CheckChangeListener listener) {
        this.listener = listener;
    }
}
